//
//  YKViewController.m
//  OCUnitPlus
//
//  Created by William Zhao on 13-7-29.
//  Copyright (c) 2013年 William Zhao. All rights reserved.
//

#import "YKViewController.h"

//analog variable
static NSUInteger _amount;

@implementation YKViewController

@synthesize priceTextField=_priceTextField;
@synthesize feeTextField=_feeTextField;
@synthesize amountLabel=_amountLabel;
@synthesize payLabel=_payLabel;

-(IBAction)sumAmount:(id)sender {
    NSUInteger price = [self.priceTextField.text integerValue];
    NSUInteger fee = [self.feeTextField.text integerValue];
    _amount = [self sum:price fee:fee];
    self.amountLabel.text = [NSString stringWithFormat:@"Amount: $%d", _amount];
}

-(IBAction)payAmount:(id)sender {
    BOOL result = [self pay];
    if(result){
        self.payLabel.text = @"pay success";
    }
    else {
        self.payLabel.text = @"pay error";
    }
}

//step1
-(NSUInteger)sum:(NSUInteger)price fee:(NSUInteger)fee {
    NSUInteger amount = price + fee;
    //discount
    if(price>200){
        amount = amount - 100;
    }
    //analog variable
    _amount = amount;
    return amount;
}

//step2
-(BOOL)pay {
    //analog variable
    if(_amount==160)
        return YES;
    else
        return NO;
}

-(void)dealloc {
    [_priceTextField release];
    [_feeTextField release];
    [_amountLabel release];
    [_payLabel release];
    [super dealloc];
}

@end
